﻿{% extends "gma/base.html" %}
{% load static %}
{% load mytag %}

<!-- CONTENT
  =====================================================================-->

{% block content %}

<div class="page__hd">
    <h1 class="page__title">
        <i class="fab fa-app-store-ios weui_grid_icon_fa" style="font-size: 32px"> </i> 产品管理
    </h1>
</div>

<div class="page__bd">
    <div class="weui-cells__title"> <i class="fab fa-app-store-ios"></i> 产品列表 </div>
    <div class="weui-cells">
        {% for app in apps %}
        <div class="weui-media-box weui-media-box_appmsg">
            <div class="weui-media-box__hd">
                <img class="weui-media-box__thumb avatar" src="{{ app.icon|cdn }}">
            </div>

            <div class="weui-media-box__bd">
                <h4 class="weui-media-box__title"> {{ app.app_name }} </h4>
                <p class="weui-media-box__desc"> {{ app.comment }} </p>
                <p class="weui-media-box__desc"> {{ app.create_time|date:"Y-m-d H:i:s" }} </p>
            </div>

            <div class="weui-cell__ft">
                <label for="switch_busy_mode_app_{{ app.id }}" class="weui-switch-cp">
                {% if app.sterilize_type == 0 %}
                    <input id="switch_busy_mode_app_{{ app.id }}" class="weui-switch-cp__input" type="checkbox" onclick="sterilizeApp('{{ app.id }}', 2)" />
                {% elif app.sterilize_type == 1 %}
                    <input id="switch_busy_mode_app_{{ app.id }}" class="weui-switch-cp__input" type="checkbox" checked="checked" onclick="sterilizeApp('{{ app.id }}', 0)" />
                {% elif app.sterilize_type == 2 %}
                    <input id="switch_busy_mode_app_{{ app.id }}" class="weui-switch-cp__input" type="checkbox" checked="checked" onclick="sterilizeApp('{{ app.id }}', 0)" />
                {% endif %}
                    <div class="weui-switch-cp__box"></div>
                </label>
            </div>
        </div>
        {% endfor %}
    </div>

    <div class="weui-cells__title"> <i class="fa fa-chair"></i> 渠道列表 </div>
    <div class="weui-cells">
        {% for channel in channels %}
        <div class="weui-media-box weui-media-box_appmsg">
            <div class="weui-media-box__bd">
                <h4 class="weui-media-box__title"> {{ channel.name }} </h4>
                <p class="weui-media-box__desc"> {{ channel.channel_code }} </p>
                <p class="weui-media-box__desc"> {{ channel.comment }} </p>
                <p class="weui-media-box__desc"> {{ channel.create_time|date:"Y-m-d H:i:s" }} </p>
            </div>

            <div class="weui-cell__ft">
                <label for="switch_busy_mode_channel_{{ channel.id }}" class="weui-switch-cp">
                {% if channel.sterilize_type == 0 %}
                    <input id="switch_busy_mode_channel_{{ channel.id }}" class="weui-switch-cp__input" type="checkbox" onclick="sterilizeChannel('{{ channel.id }}', 2)" />
                {% elif channel.sterilize_type == 1 %}
                    <input id="switch_busy_mode_channel_{{ channel.id }}" class="weui-switch-cp__input" type="checkbox" checked="checked" onclick="sterilizeChannel('{{ channel.id }}', 0)" />
                {% elif channel.sterilize_type == 2 %}
                    <input id="switch_busy_mode_channel_{{ channel.id }}" class="weui-switch-cp__input" type="checkbox" checked="checked" onclick="sterilizeChannel('{{ channel.id }}', 0)" />
                {% endif %}
                    <div class="weui-switch-cp__box"></div>
                </label>
            </div>
        </div>
        {% endfor %}
    </div>
</div>

<div class="page__ft">
    <a href="{% url 'gma:home' %}">
        <span class="bottom-logo">
           HiBao
       </span>
    </a>
</div>

{% endblock content %}


<!-- SCRIPT
  =====================================================================-->

{% block extra_js %}

<script>
function sterilizeApp(app_id, sterilize_type) {
    let url = "{% url 'gma:api_sterilize_app' %}";
    let data = {
        'app_id': app_id,
        'sterilize_type': sterilize_type,
    };

    if (sterilize_type === 0) {
        new my_ajax(url, data, '', '', () => {
            show_toast(`关闭APP过滤!`);
        });
    } else {
        new my_ajax(url, data, '', '', () => {
            show_toast(`开启APP过滤!`);
        });
    }
}

function sterilizeChannel(channel_id, sterilize_type) {
    let url = "{% url 'gma:api_sterilize_channel' %}";
    let data = {
        'channel_id': channel_id,
        'sterilize_type': sterilize_type,
    };

    if (sterilize_type === 0) {
        new my_ajax(url, data, '', '', () => {
            show_toast(`关闭渠道过滤!`);
        });
    } else {
        new my_ajax(url, data, '', '', () => {
            show_toast(`开启渠道过滤!`);
        });
    }
}
</script>

{% endblock extra_js %}